package TestSystemClient;

import javax.swing.*;
import javax.swing.Timer;

import java.awt.*;
import java.io.*;
import java.net.*;
import java.util.*;
import javax.swing.border.*;
import java.awt.event.*;

import TestSystemIO.*;
import TestSystemUtil.*;
import javax.swing.table.DefaultTableModel;

@SuppressWarnings("serial")
public class ClientMultiplayer extends JFrame {
	
	public Socket connection;
	public final Object writeLockObj = new Object();
	public final Object readLockObj = new Object();
	public InputThread inputThread;
	public OutputThread outputThread;
	
	public Protocol protocol = new Protocol();
	public ClientUtil util = new ClientUtil();
	public ArrayList<String> playerInfo = new ArrayList<String>();
	public ArrayList<String> onlineUsers = new ArrayList<String> ();
	public ArrayList<ArrayList<String>> groupInfo = new ArrayList<ArrayList<String>>();
	public Vector<Vector<String>> groupResult = new Vector<Vector<String>>();
	public ArrayList<ArrayList<JLabel>> infoLabels = new ArrayList<ArrayList<JLabel>>();
	public String selected, hostname, answer, correctAnswer;
	public Timer t, nextTurn;
	public int second=0, answerSecond, endTurnTime=10;
	public boolean isSubmited = false;
	
	public JPanel bgPanel, panelOnline, panelPlayer1, panelPlayer2, panelPlayer3, panelPlayer4, 
	panelPlay, panelStart, panelWaiting, panelResult, panelGuide, panelQuestion;
	public JButton btnLeaveGroup, btnInvite, btnStartGame, btnGuide1, btnGuide2;
	public JLabel lblPlayer1Name, lblPlayer2Name, lblPlayer3Name, lblPlayer4Name, lblPlayer1Score, lblPlayer3Score, lblPlayer2Score, lblPlayer4Score, 
	lblMultiplayer, lblHostGreeting, lblWaiting, lblLoad, lblTime, lblQuestionType, lblLevel;
	public JList<String> list;
	public JScrollPane scrollPane;
	public CardLayout c;
	public JTextPane textPaneQuestion;
	public JRadioButton rdbtnChoiceA, rdbtnChoiceB, rdbtnChoiceC, rdbtnChoiceD;
	public JButton btnSubmit;
	public JPanel panelWaitResult;
	public JLabel lblWaitResult;
	public JLabel lblYourAnswer;
	public JLabel lblSecond;
	public JLabel lblResult;
	public JLabel lblCorrectAnswer;
	public JLabel lblNextTurn;
	public JTable resultTable;
	public JScrollPane scrollPane_1;
	
	//======== CLIENT MULTI PLAYER FRAME CONSTRUCTOR =======//
	public ClientMultiplayer(Socket conn) {
		//=== COPY SOCKET, TẠO INPUT + OUTPUT THREAD, PROTOCOL ==//
		connection = conn;																//Tiếp tục sử dụng socket được truyền từ ClientSinglePlayer
		inputThread = util.makeInputThread(connection, readLockObj, protocol, this);	//Tạo Thread read input stream
		outputThread = util.makeOutputThread(connection, writeLockObj);					//Tạo Thread write output stream
		util.startSession(inputThread, outputThread);									//Start 2 thread read và write
		protocol.setState(Protocol.GROUPPLAY);											
		//=======================================================//
		
		//============ KHỞI TẠO FRAME MULTI PLAYER ==============//
		createClientMultiplayerFrame();
		infoLabels = makeLabelsList();													//Tạo một mảng chứa các Label của 4 panel để cập nhật thông tin sau này
		c = (CardLayout) panelPlay.getLayout();
		//=======================================================//
		
		//================= CLICK ONLINE LIST ===================//
		list.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				selected = list.getSelectedValue();
			}
		});
		//=======================================================//
		
		//=================== CLICK START BUTTON ================//
		btnStartGame.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				Client.messageToServer = protocol.getMessageForm() + "\n";
				synchronized(writeLockObj) {
					writeLockObj.notify();
				}
				
			}
		});
		//=======================================================//
		
		//=================PLAY TIME CALCULATION ================//
		ActionListener timeCal = new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
            	++second;
                lblTime.setText(String.format("00:%02d", second));
                if(isSubmited) {
                	t.stop();
                	isSubmited = false;
                	second = 0;
                }
                if(second == 60) {
                	lblTime.setText("01:00");
                	t.stop();
                	if(!isSubmited) {
	                	protocol.setState(Protocol.GROUPSUBMIT);
	                	Client.messageToServer = String.format(protocol.getMessageForm(), " ", second) + "\n";
	                	protocol.setState(Protocol.GROUPPLAY);
	                	synchronized(writeLockObj) {
	                		writeLockObj.notify();
	                	}
                	}
                }
            }
        };
        t = new Timer(1000, timeCal);
        //=======================================================//
        
        //================= NEXT TURN TIME COUNT ================//
      		ActionListener nextTurnTimeCal = new ActionListener() {
                  public void actionPerformed(ActionEvent evt) {
                      lblNextTurn.setText(String.format("Next Question in %d seconds", endTurnTime--));
                      if(endTurnTime == 0) {
                    	  endTurnTime = 10;
                    	  nextTurn.stop();
                    	  System.out.println(playerInfo.get(4) + " " + hostname);
                    	  if(playerInfo.get(4).equals(hostname)) {
                  			protocol.setState(Protocol.GROUPPLAY);
                  			Client.messageToServer = protocol.getMessageForm() + "\n";
                  			synchronized(writeLockObj) {
                  				writeLockObj.notify();
                  			}
                    	  }
                      }
                  }
              };
              nextTurn = new Timer(1000, nextTurnTimeCal);
        //=======================================================//
              
        //=================== CLICK LEAVE BUTTON ================//
		btnLeaveGroup.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				protocol.setState(Protocol.LEAVEGROUP);
				Client.messageToServer = protocol.getMessageForm() + "\n";
				synchronized(writeLockObj) {
					writeLockObj.notify();
				}
				try {
					Thread.sleep(100);
				} catch (InterruptedException e1) { }
				protocol.setState(Protocol.GROUPPLAY);
				Client.messageToServer = "INTERRUPT" + "\n";
				synchronized(writeLockObj) {
					writeLockObj.notify();
				}
				util.finishSession(inputThread, outputThread);
				ClientMultiplayer.this.dispose();
				ClientSinglePlayer clientSinglePlayer = new ClientSinglePlayer(connection);
				clientSinglePlayer.setVisible(true);
				clientSinglePlayer.setPlayerInfo(playerInfo);
				clientSinglePlayer.setOnlineUsers(onlineUsers);
			}
		});
		//=======================================================//
		
		//=================== CLICK INVITE BUTTON ===============//
		btnInvite.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				protocol.setState(Protocol.INVITE);
				if(selected.equals(playerInfo.get(4))) {
					list.clearSelection();
					JOptionPane.showMessageDialog(null, "You can not invite yourself", "Warning", JOptionPane.WARNING_MESSAGE);
				} else if (selected.isEmpty()) {
					JOptionPane.showMessageDialog(null, "Choose an user", "Warning", JOptionPane.WARNING_MESSAGE);
				} else {
					Client.messageToServer = String.format(protocol.getMessageForm(), selected) + "\n";
					protocol.setState(Protocol.GROUPPLAY);
					synchronized(writeLockObj) {
						writeLockObj.notify();
					}
					synchronized(readLockObj) {
						try {
							readLockObj.wait();
						} catch (InterruptedException e1) { }
					}
					if(inputThread.result.get(0).equals("ACCEPT"))
						synchronized(readLockObj) {
							try {
								readLockObj.wait();
							} catch (InterruptedException ex) {  }
					} else {
						JOptionPane.showMessageDialog(null, inputThread.result.get(1) + " declined your invite", "Declined", JOptionPane.INFORMATION_MESSAGE);
					}
				}
				protocol.setState(Protocol.GROUPPLAY);
			}
		});
		//=======================================================//
		
		//=================== CLICK SUBMIT BUTTON ===============//
		btnSubmit.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				protocol.setState(Protocol.GROUPSUBMIT);
				Client.messageToServer = String.format(protocol.getMessageForm(), answer, second) +"\n";
				synchronized(writeLockObj) {
					writeLockObj.notify();
				}
				protocol.setState(Protocol.GROUPPLAY);
				lblYourAnswer.setText(String.format(lblYourAnswer.getText(), answer));
				lblSecond.setText(String.format(lblSecond.getText(), second));
				isSubmited = true;
				c.show(panelPlay, "card6");	
				resetChoiceButton();
			}
		});
		//=======================================================//
		
		//============ CLICK CHOICE A,B,C,D BUTTON ==============//
		rdbtnChoiceA.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
		        rdbtnChoiceA.setSelected(true);
		        answer = "A";
		        rdbtnChoiceB.setSelected(false);
		        rdbtnChoiceC.setSelected(false);
		        rdbtnChoiceD.setSelected(false);
			}
		});
		rdbtnChoiceB.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				rdbtnChoiceB.setSelected(true);
				answer = "B";
		        rdbtnChoiceA.setSelected(false);
		        rdbtnChoiceC.setSelected(false);
		        rdbtnChoiceD.setSelected(false);
			}
		});
		rdbtnChoiceC.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				rdbtnChoiceC.setSelected(true);
				answer = "C";
		        rdbtnChoiceA.setSelected(false);
		        rdbtnChoiceB.setSelected(false);
		        rdbtnChoiceD.setSelected(false);
			}
		});
		rdbtnChoiceD.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				rdbtnChoiceD.setSelected(true);
				answer = "D";
		        rdbtnChoiceA.setSelected(false);
		        rdbtnChoiceB.setSelected(false);
		        rdbtnChoiceC.setSelected(false);
			}
		});
		//=======================================================//
		//======== KHI ẤN TẮT FRAME BẰNG NÚT X Ở GÓC PHẢI =======//
		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				try {
					connection.close();
					if(inputThread.isAlive() || outputThread.isAlive()) {
						util.finishSession(inputThread, outputThread);
					}
				} catch (IOException e1) { }
			}
		});
		//=======================================================//
	}
	//=======================================================//
	
	public void setPlayerInfo (ArrayList<String> info) {
		playerInfo = info;
	}
	
	//================== SET ONLINE USERS ===================//
	public void setOnlineUsers(ArrayList<String> onlineUsers) {
		this.onlineUsers = onlineUsers;
		DefaultListModel<String> model = new DefaultListModel<String> ();
		for(int i=0; i<onlineUsers.size(); i++) {
			model.addElement(onlineUsers.get(i));
		}
		list.setModel(model);
	}
	//=======================================================//
	
	//=================== SET GROUP INFO ====================//
	public void setGroupInfo(ArrayList<ArrayList<String>> infoToClient, String hostname) {
		int i;
		this.hostname = hostname;
		lblHostGreeting.setText(String.format(lblHostGreeting.getText(), hostname));
		for(i=0; i<infoToClient.size(); i++) {
			infoLabels.get(i).get(0).setText(infoToClient.get(i).get(0));
			infoLabels.get(i).get(1).setText(infoToClient.get(i).get(1));
		}
		while(i<infoLabels.size()) {
			infoLabels.get(i).get(0).setText("");
			infoLabels.get(i).get(1).setText("");
			i++;
		}
	}
	//=======================================================//
	
	//=================== SET RESULT INFO ===================//
	public void setResultInfo(Vector<Vector<String>> resultInfo) {
		lblCorrectAnswer.setText(String.format(lblCorrectAnswer.getText(), correctAnswer));
		Vector<String> columnName = new Vector<String>();
		columnName.add("Name");
		columnName.add("Score");
		columnName.add("Answer");
		columnName.add("Time");
		resultTable.setModel(new DefaultTableModel(resultInfo, columnName));
		setScoreGroup(resultInfo);
		nextTurn.start();
	}
	//=======================================================//
	
	public void setScoreGroup(Vector<Vector<String>> resultInfo) {
		for(int i=0; i<resultInfo.size(); i++) {
			infoLabels.get(i).get(1).setText(resultInfo.get(i).get(1));
		}
	}
	//=============== GET QUESTION FROM SERVER ==============//
	public void setQuestion(ArrayList<String> question) {
		switch(question.get(1)) {
		case "1": lblLevel.setText("Hard"); break;
		case "2": lblLevel.setText("Medium"); break;
		case "3": lblLevel.setText("Easy"); break;
		}
		lblQuestionType.setText(question.get(2));
		textPaneQuestion.setText(question.get(3));
		rdbtnChoiceA.setText(question.get(4));
		rdbtnChoiceB.setText(question.get(5));
		rdbtnChoiceC.setText(question.get(6));
		rdbtnChoiceD.setText(question.get(7));
	}
	//=======================================================//
	
	public ArrayList<ArrayList<JLabel>> makeLabelsList() {
		ArrayList<ArrayList<JLabel>> labels = new ArrayList<ArrayList<JLabel>>();
		ArrayList<JLabel> item1 = new ArrayList<JLabel>();
		ArrayList<JLabel> item2 = new ArrayList<JLabel>();
		ArrayList<JLabel> item3 = new ArrayList<JLabel>();
		ArrayList<JLabel> item4 = new ArrayList<JLabel>();
		item1.add(lblPlayer1Name);
		item1.add(lblPlayer1Score);
		labels.add(item1);
		item2.add(lblPlayer2Name);
		item2.add(lblPlayer2Score);
		labels.add(item2);
		item3.add(lblPlayer3Name);
		item3.add(lblPlayer3Score);
		labels.add(item3);
		item4.add(lblPlayer4Name);
		item4.add(lblPlayer4Score);
		labels.add(item4);
		return labels;
	}
	public void groupNotExist() {
		Client.messageToServer = "INTERRUPT" + "\n";
		synchronized(writeLockObj) {
			writeLockObj.notify();
		}
		util.finishSession(inputThread, outputThread);
		ClientMultiplayer.this.dispose();
		ClientSinglePlayer clientSinglePlayer = new ClientSinglePlayer(connection);
		clientSinglePlayer.setVisible(true);
		clientSinglePlayer.setPlayerInfo(playerInfo);
		clientSinglePlayer.setOnlineUsers(onlineUsers);
	}
	
	//===================== NEXT TURN =======================//
	public void nextTurn() {
		protocol.setState(Protocol.GROUPPLAY);
		if(hostname.equals(playerInfo.get(4))) {
			Client.messageToServer = protocol.getMessageForm() + "\n";
			synchronized(writeLockObj) {
				writeLockObj.notify();
			}
		}
	}
	//=======================================================//
	
	//=============== RESET 4 BUTTON ĐÁP ÁN =================//
	public void resetChoiceButton() {
		rdbtnChoiceA.setSelected(false);       
		rdbtnChoiceB.setSelected(false);       
		rdbtnChoiceC.setSelected(false);       
		rdbtnChoiceD.setSelected(false);    
	}
	//=======================================================//
	
	//=========== TẠO FRAME CLIENT MULTIPLAYER ==============//
	public void createClientMultiplayerFrame() {
		lblPlayer1Name = new JLabel("New label");
		lblPlayer1Score = new JLabel("New label");
		lblPlayer2Name = new JLabel("New label");
		lblPlayer2Score = new JLabel("New label");
		lblPlayer3Name = new JLabel("New label");
		lblPlayer3Score = new JLabel("New label");
		lblPlayer4Name = new JLabel("New label");
		lblPlayer4Score = new JLabel("New label");
		lblWaiting = new JLabel("Waiting for Host");
		lblHostGreeting = new JLabel("%s, You're host of this group !");
		lblTime = new JLabel("00:00");
		lblLoad = new JLabel("");
		lblQuestionType = new JLabel("Question");
		lblLevel = new JLabel("Level");
		lblMultiplayer = new JLabel("Test System Multiplayer");
		lblWaitResult = new JLabel("Waiting for other players");
		lblYourAnswer = new JLabel("Your Answer : %s");
		lblSecond = new JLabel("At %s second");
		
		panelPlayer1 = new JPanel();
		panelPlayer2 = new JPanel();
		panelPlayer3 = new JPanel();
		panelPlayer4 = new JPanel();
		panelStart = new JPanel();
		panelPlay = new JPanel();
		panelWaiting = new JPanel();
		panelGuide = new JPanel();
		panelResult = new JPanel();
		panelQuestion = new JPanel();
		panelOnline = new JPanel();
		panelWaitResult = new JPanel();
		
		btnStartGame = new JButton("Start");
		btnGuide1 = new JButton("Play Guide");
		btnGuide2 = new JButton("Play Guide");
		btnSubmit = new JButton("Submit");
		btnLeaveGroup = new JButton("Leave Group");
		btnInvite = new JButton("Invite");
		
		rdbtnChoiceA = new JRadioButton("New radio button");
		rdbtnChoiceB = new JRadioButton("New radio button");
		rdbtnChoiceC = new JRadioButton("New radio button");
		rdbtnChoiceD = new JRadioButton("New radio button");
		scrollPane = new JScrollPane();
		list = new JList<String>();
		textPaneQuestion = new JTextPane();
		
		bgPanel = new JPanel() {
			public void paintComponent(Graphics g) {
				Image image = Toolkit.getDefaultToolkit().getImage(ClientLogin.class.getResource("/resources/background.jpg"));
				g.drawImage(image, 0, 0, image.getWidth(null), image.getHeight(null), this);
			}
		};
		
		setTitle("Multiplayer");
		setResizable(false);
		setSize(new Dimension(1000, 600));
		setLocationRelativeTo(null);
		getContentPane().setLayout(null);
		getContentPane().add(bgPanel);
		
		bgPanel.setBounds(0, 0, 994, 572);
		bgPanel.setLayout(null);
		bgPanel.add(panelPlayer1);
		bgPanel.add(panelPlayer2);
		bgPanel.add(panelPlayer3);
		bgPanel.add(panelPlayer4);
		bgPanel.add(panelPlay);
		bgPanel.add(lblMultiplayer);
		bgPanel.add(panelOnline);
		bgPanel.add(btnLeaveGroup);
		
		panelPlayer1.setOpaque(false);
		panelPlayer1.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Player 1", TitledBorder.CENTER, TitledBorder.TOP, null, null));
		panelPlayer1.setBounds(0, 0, 161, 176);
		panelPlayer1.setLayout(null);
		panelPlayer2.setOpaque(false);
		panelPlayer2.setBorder(new TitledBorder(null, "Player 2", TitledBorder.CENTER, TitledBorder.TOP, null, null));
		panelPlayer2.setBounds(0, 383, 161, 189);
		panelPlayer2.setLayout(null);
		panelPlayer3.setOpaque(false);
		panelPlayer3.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Player 3", TitledBorder.CENTER, TitledBorder.TOP, null, null));
		panelPlayer3.setBounds(633, 0, 161, 176);
		panelPlayer3.setLayout(null);
		panelPlayer4.setOpaque(false);
		panelPlayer4.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Player 4", TitledBorder.CENTER, TitledBorder.TOP, null, null));
		panelPlayer4.setBounds(633, 396, 161, 176);
		panelPlayer4.setLayout(null);
		panelPlay.setOpaque(false);
		panelPlay.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Question", TitledBorder.CENTER, TitledBorder.TOP, null, null));
		panelPlay.setBounds(171, 83, 452, 411);
		panelPlay.setLayout(new CardLayout(0, 0));
		
		panelPlayer1.add(lblPlayer1Name);
		panelPlayer1.add(lblPlayer1Score);
		panelPlayer2.add(lblPlayer2Name);
		panelPlayer2.add(lblPlayer2Score);
		panelPlayer3.add(lblPlayer3Name);
		panelPlayer3.add(lblPlayer3Score);
		panelPlayer4.add(lblPlayer4Name);
		panelPlayer4.add(lblPlayer4Score);
		
		lblPlayer1Name.setFont(new Font("Arial", Font.BOLD, 17));
		lblPlayer1Name.setHorizontalAlignment(SwingConstants.CENTER);
		lblPlayer1Name.setBounds(10, 45, 141, 29);
		lblPlayer1Score.setHorizontalAlignment(SwingConstants.CENTER);
		lblPlayer1Score.setFont(new Font("Segoe Print", Font.PLAIN, 14));
		lblPlayer1Score.setBounds(24, 85, 112, 29);
		lblPlayer2Name.setHorizontalAlignment(SwingConstants.CENTER);
		lblPlayer2Name.setFont(new Font("Arial", Font.BOLD, 16));
		lblPlayer2Name.setBounds(10, 42, 141, 29);
		lblPlayer2Score.setHorizontalAlignment(SwingConstants.CENTER);
		lblPlayer2Score.setFont(new Font("Segoe Print", Font.PLAIN, 14));
		lblPlayer2Score.setBounds(23, 82, 112, 29);
		lblPlayer3Name.setHorizontalAlignment(SwingConstants.CENTER);
		lblPlayer3Name.setFont(new Font("Arial", Font.BOLD, 16));
		lblPlayer3Name.setBounds(10, 38, 141, 29);
		lblPlayer3Score.setHorizontalAlignment(SwingConstants.CENTER);
		lblPlayer3Score.setFont(new Font("Segoe Print", Font.PLAIN, 14));
		lblPlayer3Score.setBounds(27, 78, 112, 29);
		lblPlayer4Name.setHorizontalAlignment(SwingConstants.CENTER);
		lblPlayer4Name.setFont(new Font("Arial", Font.BOLD, 16));
		lblPlayer4Name.setBounds(10, 39, 141, 29);
		lblPlayer4Score.setHorizontalAlignment(SwingConstants.CENTER);
		lblPlayer4Score.setFont(new Font("Segoe Print", Font.PLAIN, 14));
		lblPlayer4Score.setBounds(26, 107, 112, 29);
		
		panelPlay.add(panelStart, "card1");
		panelPlay.add(panelWaiting, "card2");
		panelPlay.add(panelQuestion, "card3");
		panelPlay.add(panelResult, "card4");
		panelPlay.add(panelGuide, "card5");
		panelPlay.add(panelWaitResult, "card6");
	
		panelStart.setOpaque(false);
		panelStart.setLayout(null);
		panelWaiting.setOpaque(false);
		panelWaiting.setLayout(null);
		panelResult.setOpaque(false);
		panelResult.setLayout(null);
		
		lblResult = new JLabel("RESULT");
		lblResult.setHorizontalAlignment(SwingConstants.CENTER);
		lblResult.setFont(new Font("Segoe Print", Font.BOLD, 18));
		lblResult.setBounds(126, 33, 194, 14);
		panelResult.add(lblResult);
		lblCorrectAnswer = new JLabel("Correct Answer : %s");
		lblCorrectAnswer.setFont(new Font("Arial", Font.PLAIN, 15));
		lblCorrectAnswer.setHorizontalAlignment(SwingConstants.CENTER);
		lblCorrectAnswer.setBounds(122, 71, 198, 24);
		panelResult.add(lblCorrectAnswer);
		
		lblNextTurn = new JLabel("");
		lblNextTurn.setBounds(138, 267, 163, 14);
		panelResult.add(lblNextTurn);
		
		scrollPane_1 = new JScrollPane();
		scrollPane_1.setBounds(69, 152, 300, 104);
		panelResult.add(scrollPane_1);
		
		resultTable = new JTable();
		scrollPane_1.setViewportView(resultTable);
		resultTable.setFillsViewportHeight(true);
		resultTable.setModel(new DefaultTableModel(
			new Object[][] {
				{null, null, null, null},
				{null, null, null, null},
				{null, null, null, null},
				{null, null, null, null},
			},
			new String[] {
				"Name", "Score", "Answer", "Time"
			}
		) {
			boolean[] columnEditables = new boolean[] {
				true, false, true, true
			};
			public boolean isCellEditable(int row, int column) {
				return columnEditables[column];
			}
		});
		panelGuide.setOpaque(false);
		panelQuestion.setOpaque(false);
		panelQuestion.setLayout(null);
		panelOnline.setOpaque(false);
		panelOnline.setBorder(new TitledBorder(null, "Online List", TitledBorder.CENTER, TitledBorder.ABOVE_TOP, null, null));
		panelOnline.setBounds(806, 6, 188, 566);
		panelOnline.setLayout(null);
		panelWaitResult.setOpaque(false);
		panelWaitResult.setLayout(null);
		
		panelOnline.add(scrollPane);
		panelStart.add(lblHostGreeting);
		panelStart.add(btnStartGame);
		panelStart.add(btnGuide1);
		panelWaiting.add(lblWaiting);
		panelWaiting.add(lblLoad);
		panelWaiting.add(btnGuide2);
		panelQuestion.add(lblTime);
		panelQuestion.add(textPaneQuestion);
		panelQuestion.add(rdbtnChoiceA);
		panelQuestion.add(rdbtnChoiceB);
		panelQuestion.add(rdbtnChoiceC);
		panelQuestion.add(rdbtnChoiceD);
		panelQuestion.add(btnSubmit);
		panelQuestion.add(lblQuestionType);
		panelQuestion.add(lblLevel);
		panelOnline.add(btnInvite);
		panelWaitResult.add(lblWaitResult);
		panelWaitResult.add(lblYourAnswer);
		panelWaitResult.add(lblSecond);
		
		lblHostGreeting.setHorizontalAlignment(SwingConstants.CENTER);
		lblHostGreeting.setFont(new Font("Segoe Print", Font.BOLD, 16));
		lblHostGreeting.setBounds(58, 42, 337, 79);
		btnStartGame.setFont(new Font("Segoe Print", Font.PLAIN, 16));
		btnStartGame.setBounds(143, 156, 144, 35);
		btnGuide1.setFont(new Font("Segoe Print", Font.PLAIN, 16));
		btnGuide1.setBounds(143, 232, 144, 35);
		lblWaiting.setHorizontalAlignment(SwingConstants.CENTER);
		lblWaiting.setFont(new Font("Segoe Print", Font.BOLD, 16));
		lblWaiting.setBounds(47, 71, 336, 63);
		lblLoad.setFont(new Font("Segoe Print", Font.PLAIN, 13));
		lblLoad.setHorizontalAlignment(SwingConstants.CENTER);
		lblLoad.setBounds(93, 145, 236, 14);
		btnGuide2.setFont(new Font("Segoe Print", Font.PLAIN, 16));
		btnGuide2.setBounds(146, 232, 144, 35);
		lblTime.setFont(new Font("Tahoma", Font.BOLD, 16));
		lblTime.setHorizontalAlignment(SwingConstants.CENTER);
		lblTime.setBounds(167, 11, 109, 30);
		textPaneQuestion.setEditable(false);
		textPaneQuestion.setBounds(32, 102, 378, 86);
		rdbtnChoiceA.setBounds(72, 200, 291, 23);
		rdbtnChoiceB.setBounds(72, 235, 291, 23);
		rdbtnChoiceC.setBounds(72, 270, 291, 23);
		rdbtnChoiceD.setBounds(72, 305, 291, 23);
		btnSubmit.setFont(new Font("Segoe Print", Font.PLAIN, 12));
		btnSubmit.setBounds(171, 354, 89, 23);
		lblQuestionType.setBounds(32, 76, 73, 14);
		lblLevel.setBounds(117, 76, 64, 14);
		lblMultiplayer.setFont(new Font("Segoe Print", Font.BOLD, 18));
		lblMultiplayer.setHorizontalAlignment(SwingConstants.CENTER);
		lblMultiplayer.setHorizontalTextPosition(SwingConstants.CENTER);
		lblMultiplayer.setBounds(171, 24, 452, 48);
		btnLeaveGroup.setFont(new Font("Segoe Print", Font.PLAIN, 14));
		btnLeaveGroup.setBounds(345, 521, 121, 23);
		scrollPane.setBounds(20, 40, 146, 181);
		list.setRequestFocusEnabled(false);
		list.setFocusCycleRoot(true);
		list.setBorder(new CompoundBorder());
		scrollPane.setViewportView(list);
		btnInvite.setFont(new Font("Segoe Print", Font.PLAIN, 14));
		btnInvite.setBounds(49, 258, 89, 23);
		lblWaitResult.setHorizontalAlignment(SwingConstants.CENTER);
		lblWaitResult.setFont(new Font("Segoe Print", Font.BOLD, 18));
		lblWaitResult.setBounds(68, 36, 323, 46);
		lblYourAnswer.setFont(new Font("Segoe Print", Font.PLAIN, 16));
		lblYourAnswer.setBounds(68, 128, 146, 24);
		lblSecond.setFont(new Font("Segoe Print", Font.PLAIN, 16));
		lblSecond.setHorizontalAlignment(SwingConstants.CENTER);
		lblSecond.setBounds(244, 133, 135, 14);	
	}
}
